///////////////////////////////////////////////////////////
//  CAboutView.cpp
//  Implementation of the Class CAboutView
//  Created on:      19-Oct-2013 11:36:32 AM
//  Original author: Jakkaphan Aiemcharoenjit
///////////////////////////////////////////////////////////

#include "CAboutView.h"
#include "ControlCommand.h"
#include "CurrentCommand.h"
#include "stdafx.h"

using namespace UI;
using namespace UI::CMD;

#define LOCAL_URL "rom://about.html"

CAboutView::CAboutView(IWindowDirector* director)
{
  this->m_type = IViewCtrl::ABOUTVIEW_T;
  this->m_parrentWnd = director;

  // call initialize for create all UI.
  Initialize();

	m_webView = s3eWebViewCreate();

	s3eWebViewNavigate(m_webView, LOCAL_URL);
}

CAboutView::~CAboutView()
{
	if(m_webView)
	{
		s3eWebViewDestroy(m_webView);
		m_webView = NULL;
	}
}

UI::IViewCtrl::ViewType CAboutView::GetType() const 
{

	return  this->m_type;
}


void CAboutView::Initialize()
{
  this->SetAttribute("x1", 0);
  this->SetAttribute("y1", 0);
  this->SetAttribute("width", "100%");
  this->SetAttribute("height", "90%");
  this->SetAttribute("backgroundColour", CColour(COLOUR_PAGE));

  // Create navigationbar and set right button name
  this->m_navigationBar = CreateNavigationBar(CAttributes()
    .Set("name", "navBar")
    .Set("title", "About")
    .Set("x1",      0)
    .Set("y1",      0)
    .Set("width",   "100%")
    .Set("height",  "10%"));

  // Setting event handler for handling navigation bar click
  this->m_navigationBar->SetEventHandler("clicknavigationbar", this, &CAboutView::OnClickedNavigationBar);

  // Add navigation bar in view
  this->AddChild(this->m_navigationBar);

	int totalWidth = s3eSurfaceGetInt(S3E_SURFACE_WIDTH);
	int totalHeight = s3eSurfaceGetInt(S3E_SURFACE_HEIGHT);

	m_webX = 0;
	m_webY = (totalHeight * 10) / 100;
	m_webW = totalWidth;
	m_webH = (totalHeight * 80) / 100;
}


void CAboutView::Refresh()
{
}


void CAboutView::ShowView(bool show)
{
  this->SetAttribute("visible", show);
	if(show)
		s3eWebViewShow(m_webView, m_webX, m_webY, m_webW, m_webH);
	else
		s3eWebViewHide(m_webView);
}

bool UI::CAboutView::OnClickedNavigationBar( CNavigationBar *naviBar, int button )
{
  switch(button)
  {
  case S3E_NUI_NAVIGATION_BAR_BUTTON_LEFT:
    {

    }
    break;
  case S3E_NUI_NAVIGATION_BAR_BUTTON_RIGHT:
    {

    }
    break;
  default: break;
  }
  return true;
}
